package com.situ.mall.controller.back;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.mall.common.ServerResponse;
import com.situ.mall.entity.Product;
import com.situ.mall.service.IProductService;

@RequestMapping("/product")
@Controller
public class ProductController {
	@Autowired
	private IProductService productService;

	@RequestMapping("/getProductPage")
	public String getProductPage() {
		return "/product/product_list";
	}
	
	@RequestMapping("/list")
	@ResponseBody
	public List<Product> list() {
		return productService.list();
	}
	
	@RequestMapping("/pageList")
	@ResponseBody
	public ServerResponse pageList(Integer page, Integer limit, Product product, Date time) {
		System.out.println(time);
		ServerResponse serverResponse = productService.pageList(page, limit, product);
		System.out.println(serverResponse);
		return serverResponse;
	}
	
	@RequestMapping("/deleteById")
	@ResponseBody
	public ServerResponse deleteById(Integer id) {
		return productService.deleteById(id);
	}
	
	@RequestMapping("/deleteAll")
	@ResponseBody
	public ServerResponse deleteAll(String ids) {
		return productService.deleteAll(ids);
	}
	
	@RequestMapping("/getAddPage")
	public String getAddPage() {
		return "/product/product_add";
	}
	
	@RequestMapping("/add")
	@ResponseBody
	public ServerResponse add(Product product) {
		return productService.add(product);
	}
}
